package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.redis.RedisKey;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.dto.LitterBsCityDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BsCityMapper;
import com.ruoyi.system.domain.BsCity;
import com.ruoyi.system.service.IBsCityService;

/**
 * 城市设置Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-11-05
 */
@Service
public class BsCityServiceImpl implements IBsCityService 
{
    @Autowired
    private BsCityMapper bsCityMapper;
    @Autowired
    private RedisCache redisCache;

    /**
     * 查询城市设置
     * 
     * @param cityId 城市设置ID
     * @return 城市设置
     */
    @Override
    public BsCity selectBsCityById(Long cityId)
    {
        return bsCityMapper.selectBsCityById(cityId);
    }

    /**
     * 查询城市设置列表
     * 
     * @param bsCity 城市设置
     * @return 城市设置
     */
    @Override
    public List<BsCity> selectBsCityList(BsCity bsCity)
    {
        List<BsCity> bsCities = bsCityMapper.selectBsCityList(bsCity);
        return bsCities;
    }

    @Override
    public List<LitterBsCityDTO> selectBsCityListC_N(String cityName) {
        if(StringUtils.isEmpty(cityName)){
            if(!redisCache.isHasKey(RedisKey.GEO_SYSTEM_CITY)) {
                System.out.println("selectBsCityListC_N>>>>>>>>>>>>nononononononocache");

                List<LitterBsCityDTO> litterBsCityDTOList = bsCityMapper.selectBsCityC_NList(cityName);
                redisCache.setCacheList(RedisKey.GEO_SYSTEM_CITY,litterBsCityDTOList);
                return litterBsCityDTOList;
            }else{
                System.out.println("selectBsCityListC_N>>>>>>>>>>>>cachecachecachecachecachecache");
               return redisCache.getCacheList(RedisKey.GEO_SYSTEM_CITY);
            }
        }else{
            return bsCityMapper.selectBsCityC_NList(cityName);
        }
    }

    /**
     * 新增城市设置
     * 
     * @param bsCity 城市设置
     * @return 结果
     */
    @Override
    public int insertBsCity(BsCity bsCity)
    {
        return bsCityMapper.insertBsCity(bsCity);
    }

    /**
     * 修改城市设置
     * 
     * @param bsCity 城市设置
     * @return 结果
     */
    @Override
    public int updateBsCity(BsCity bsCity)
    {
        return bsCityMapper.updateBsCity(bsCity);
    }

    /**
     * 批量删除城市设置
     * 
     * @param cityIds 需要删除的城市设置ID
     * @return 结果
     */
    @Override
    public int deleteBsCityByIds(Long[] cityIds)
    {
        return bsCityMapper.deleteBsCityByIds(cityIds);
    }

    /**
     * 删除城市设置信息
     * 
     * @param cityId 城市设置ID
     * @return 结果
     */
    @Override
    public int deleteBsCityById(Long cityId)
    {
        return bsCityMapper.deleteBsCityById(cityId);
    }
}
